﻿namespace dot_in.HTWKAidStation.Client.Mensa
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Threading.Tasks;

    public static class MensaParser
    {
        public static List<Mensa> GetAllMensae(string html)
        {
            return ParseOption(html);
        }

        private static string FilterHtml(string html)
        {
            return Regex.Match(html, "<select name=.location.[^>]*>(.+?)(?=</select>)").Value;
        }

        private static List<Mensa> ParseOption(string html)
        {
            html = FilterHtml(html);
            return
                Regex.Matches(html, @"<option value=.(\d+).>([^<]+)</option>").Cast<Match>().Select(
                    match => new Mensa(match.Groups[2].Value, Convert.ToInt32(match.Groups[1].Value))).ToList();
        }
    }
}
